// react
import React from "react";
import ReactDOM from "react-dom/client";
// router
import { RouterProvider } from "react-router-dom";
import createAppRouter from "routes/Router";
// lib
import { App, ConfigProvider } from "antd";
import dayjs from "dayjs";
import NP from "number-precision";
// components
import Interaction from "components/Interaction";
// 国际化
import "dayjs/locale/zh-cn";
import locale from "antd/locale/zh_CN";
// 样式
import "style/relia.scss";
// config
import { APP_MODE } from "config/env";
import { REACT_STRICT_MODE } from "config/setting";
import { ANT_DESIGN_DEFAULT_THEME } from "style/theme";
// script & methods & public
import logUtils from "utils/logUtils";
// state
import { initUserState } from "state/global";
// 其它
import reportWebVitals from "./reportWebVitals";

// dayjs的国际化
dayjs.locale("zh-cn");
// 数字精度
NP.enableBoundaryChecking(false);

// render函数
function run() {
  logUtils.console.log(`APP处于${APP_MODE}模式运行`);

  initUserState();

  const router = createAppRouter();

  const root = ReactDOM.createRoot(
    document.getElementById("root") as HTMLElement,
  );

  // 是否使用严格模式
  if (REACT_STRICT_MODE) {
    root.render(
      <React.StrictMode>
        <ConfigProvider locale={locale} theme={ANT_DESIGN_DEFAULT_THEME}>
          <App>
            <Interaction />
            <RouterProvider router={router} />
          </App>
        </ConfigProvider>
      </React.StrictMode>,
    );
  } else {
    root.render(
      <ConfigProvider locale={locale} theme={ANT_DESIGN_DEFAULT_THEME}>
        <App>
          <Interaction />
          <RouterProvider router={router} />
        </App>
      </ConfigProvider>,
    );
  }
}
// app run
run();

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
